// 思路：栈是先进后出，队列是先进先出，用两个栈，输入栈和输出栈，分别用来处理push和pop操作

function MyQueue() {
    this.stackIn = []
    this.stackOut = []
}

MyQueue.prototype.push = function (x) {
    this.stackIn.push(x)
}

MyQueue.prototype.pop = function () {
    if (this.stackOut.length) {
        return this.stackOut.pop()
    }
    while (this.stackIn.length) {
        this.stackOut.push(this.stackIn.pop())
    }
    return this.stackOut.pop()
}

MyQueue.prototype.peek = function () {
    let val = this.pop()
    this.stackOut.push(val)
    return val
}

MyQueue.prototype.empty = function () {
    return !this.stackIn.length && !this.stackOut.length
}